package com.pureut.system.controller;

import java.util.Arrays;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.system.domain.vo.SubjectRequestVo;
import com.pureut.system.domain.vo.SupplierAccessVo;
import com.pureut.system.service.ISubjectRequestService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2024-12-05 15:50:50
 * @Desc: 实验品申请Controller
 */
@RestController
@RequestMapping("/subject/request")
public class SubjectRequestController extends BaseController {

    /**
     * 实验品申请Service
     */
    @Resource
    private ISubjectRequestService subjectRequestService;

    /**
     * 查询实验品申请列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("subjectRequest-list")
    @GetMapping("/list")
    public TableDataInfo list(SubjectRequestVo subjectRequestVo) {
        startPage();
        return getDataTable(subjectRequestService.queryPage(subjectRequestVo));
    }



    /**
     * 获取实验品申请详细信息
     * @param: id 实验品申请主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("subjectRequest-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(subjectRequestService.getInfoById(id));
    }

    /**
     * 新增实验品申请
     * @param: subjectRequest 实验品申请对象
     * @return: Json工具类对象
     */
    @Log(title = "新增实验品申请", businessType = BusinessType.INSERT)
    //    @SaCheckPermission("subjectRequest-add")
    @PostMapping
    public AjaxResult add(@RequestBody SubjectRequestVo subjectRequestVo) {
        return toAjax(subjectRequestService.save(subjectRequestVo));
    }

    /**
     * 修改实验品申请
     * @param: subjectRequest 实验品申请对象
     * @return: Json工具类对象
     */
    @Log(title = "修改实验品申请", businessType = BusinessType.UPDATE)
    //    @SaCheckPermission("subjectRequest-edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SubjectRequestVo subjectRequestVo) {
        return toAjax(subjectRequestService.updateById(subjectRequestVo));
    }

    /**
     * 删除实验品申请
     * @param: id 实验品申请主键
     * @return: Json工具类对象
     */
    @Log(title = "删除实验品申请", businessType = BusinessType.DELETE)
    //    @SaCheckPermission("subjectRequest-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(subjectRequestService.removeByIds(Arrays.asList(ids)));
    }

    /**
     * 获取实验品申请 初始化信息
     * @param: id 样品申请主键
     * @return: Json工具类对象
     */
    @GetMapping(value = "/infoInit")
    public AjaxResult infoInit() {
        return AjaxResult.success(subjectRequestService.infoInit());
    }

    /**
     * 审核
     * @param: supplierAccess 供应商准入对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("supplierAccess-edit")
    @PutMapping("/examine")
    public AjaxResult examine(@RequestBody SubjectRequestVo subjectRequestVo) {
        return toAjax(subjectRequestService.examine(subjectRequestVo));
    }
}
